package ltu.thole;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class AddDevice extends Activity {
	
	private EditText name;
	private EditText address;
	private EditText port;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_device);
    }
	
	public void buttonClick(View view) {
		
		if (view.getId() == R.id.button_addDevice) {
			addDevice();
			this.finish();
		} else if (view.getId() == R.id.button_addDeviceCancel) {
			super.finish();
		}
		
	}
	
	public void addDevice() {
		
		name = (EditText) findViewById(R.id.editText_name);
		address = (EditText) findViewById(R.id.editText_address);
		port = (EditText) findViewById(R.id.editText_port);
		
		String resultName = name.getText().toString();
		String resultAddress = address.getText().toString();
		String resultPort = port.getText().toString();
		
		Intent data = new Intent();
		data.putExtra("name", resultName);
		data.putExtra("address", resultAddress);
		data.putExtra("port", resultPort);
		setResult(RESULT_OK, data);
		
	}
	
}
